angular.module('myApp.pages.score.analysis', [])
// 定义路由
.config(['$routeProvider', function($routeProvider) {
    $routeProvider.when('/score/company/analysis/:id/:name', {
        templateUrl: 'pages/score/company/detail/analysis.html',
        controller: 'ScoreCompanyAnalysisCtrl'
    })
}])
// 企业评分分析页面控制器
.controller('ScoreCompanyAnalysisCtrl', function($scope,$http,$CONST,$routeParams,$location,$interval) {
    /**
     * 生成环形图
     */
    //被评分公司的信息
    $scope.companyData=[];
      $scope.circularScore = [
            { value: 80, color:  '#f5ac48'},
            { value:20, color:  '#fce6c8'}
      ];
    //请求公司信息
      $http({
            method:'POST',
            url:$CONST.$IP+'score/v1/showCompanyScore',
            data:{
                  companyId: $routeParams.id,
                  companyName: decodeURIComponent($routeParams.name)
            }
      }).then(function successCallback(res) {
            // 请求成功执行代码,将分数传给companyData
            $scope.companyData=res.data.data.data;
            $scope.circularScore[0].value=(res.data.data.data.totalScore)*1;
            $scope.circularScore[1].value=100-(res.data.data.data.totalScore)*1;

      }, function errorCallback(res) {
            alert('数据加载失败');
      });

      /**
       * 形成圆形图案
       * @param data
       */
    $scope.createDoughnutChart = function(data) {
        var ctx = document.getElementById("myChart").getContext("2d");
        new Chart(ctx).Doughnut(data, { segmentStrokeWidth: 1, percentageInnerCutout: 80 });
    };

//调用函数，生成圆形图案
      $scope.createDoughnutChart($scope.circularScore);

      //返回按钮点击事件
      $scope.backCompanyList = function () {
            $location.path('/score/company');
      }
});